﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using log4net;
using log4net.Config;

namespace PefStudio.Services
{
    [Export(LoggingService.Contract, typeof(ILoggingService))]
    sealed class Log4NetLoggingService : ILoggingService
    {
        readonly ILog _log;

        public Log4NetLoggingService()
        {
            XmlConfigurator.ConfigureAndWatch(new FileInfo(typeof(Log4NetLoggingService).Assembly.Location + ".config"));
            _log = LogManager.GetLogger(typeof(Log4NetLoggingService));
        }

        public void Debug(object message)
        {
            _log.Debug(message);
        }

        public void DebugFormatted(string format, params object[] args)
        {
            _log.DebugFormat(CultureInfo.InvariantCulture, format, args);
        }

        public void Info(object message)
        {
            _log.Info(message);
        }

        public void InfoFormatted(string format, params object[] args)
        {
            _log.InfoFormat(CultureInfo.InvariantCulture, format, args);
        }

        public void Warn(object message)
        {
            _log.Warn(message);
        }

        public void Warn(object message, Exception exception)
        {
            _log.Warn(message, exception);
        }

        public void WarnFormatted(string format, params object[] args)
        {
            _log.WarnFormat(CultureInfo.InvariantCulture, format, args);
        }

        public void Error(object message)
        {
            _log.Error(message);
        }

        public void Error(object message, Exception exception)
        {
            _log.Error(message, exception);
        }

        public void ErrorFormatted(string format, params object[] args)
        {
            _log.ErrorFormat(CultureInfo.InvariantCulture, format, args);
        }

        public void Fatal(object message)
        {
            _log.Fatal(message);
        }

        public void Fatal(object message, Exception exception)
        {
            _log.Fatal(message, exception);
        }

        public void FatalFormatted(string format, params object[] args)
        {
            _log.FatalFormat(CultureInfo.InvariantCulture, format, args);
        }

        public bool IsDebugEnabled
        {
            get
            {
                return _log.IsDebugEnabled;
            }
        }

        public bool IsInfoEnabled
        {
            get
            {
                return _log.IsInfoEnabled;
            }
        }

        public bool IsWarnEnabled
        {
            get
            {
                return _log.IsWarnEnabled;
            }
        }

        public bool IsErrorEnabled
        {
            get
            {
                return _log.IsErrorEnabled;
            }
        }

        public bool IsFatalEnabled
        {
            get
            {
                return _log.IsFatalEnabled;
            }
        }
    }
}
